﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace _395_2d
{
    public class BoundingBox
    {
        public Vector2 topLeft;
        public Vector2 size;

        public BoundingBox(Vector2 TL, Vector2 sz)
        {
            topLeft = TL;
            size = sz;
        }

        public bool overlap(BoundingBox b)
        {
            return b.topLeft.X < topLeft.X + size.X &&
                   b.topLeft.Y < topLeft.Y + size.Y &&
                   b.topLeft.X + b.size.X > topLeft.X &&
                   b.topLeft.Y + b.size.Y > topLeft.Y;
        }

        public void keepInside(BoundingBox b)
        {
            if ( topLeft.X < b.topLeft.X )
                topLeft.X = b.topLeft.X;

            if ( topLeft.Y < b.topLeft.Y )
                topLeft.Y = b.topLeft.Y;

            if (topLeft.X + size.X > b.topLeft.X + b.size.X)
                topLeft.X = b.topLeft.X + b.size.X - size.X;

            if (topLeft.Y + size.Y > b.topLeft.Y + b.size.Y)
                topLeft.Y = b.topLeft.Y + b.size.Y - size.Y;
        }
    }
}
